/**
 * 封装HTTP请求的方法;状态码为200时，直接返回data,当非此情况时，返回fail(res)
 */
const httpPost = (url, data, success, fail) => {
  wx.request({
    url: url,
    data: data,
    method: 'POST',
    responseType: 'text',
    header: {
      "Content-Type": "application/json",
    },
    dataType: 'json',
    success: function (res) {

      if (res.statusCode === 200) {
        success(res.data)
      } else {
        fail(res)
      }
    },
    fail: function (res) {
      fail(res);
    }
  });
}

const httpGet = (url, data, success, fail) => {
  console.log(data,url)
  wx.request({
    url: url,
    data: data,
    method: 'GET',
    dataType: 'json',
    header: {
      "Content-Type": "application/json",
    },
    responseType: 'text',
    success: function(res) {
      if (res.statusCode === 200) {
        success(res.data)
      } else {
        fail(res)
      }
    },
    fail: function(res) {
      fail(res);
    }
  });
}



export const get = httpGet;
export const post = httpPost;